from django.conf.urls import url
from rest_framework.routers import DefaultRouter

from . import views


urlpatterns = [
    # url(r'^books/$', views.BookListView.as_view()),
    # url(r'^books/(?P<pk>\d+)/$', views.BookDetailView.as_view()),

    # 演示APIView
    # url(r'^books/$', views.BookListView.as_view()),

    # 演示GenericAPIView详情视图
    # url(r'^books/(?P<pk>\d+)/$', views.BookDetailView.as_view()),

    # 演示GenericAPIView列表视图
    # url(r'^books/$', views.BookListView.as_view()),


    # 视图集ViewSet
    # url(r'^books/$', views.BookInfoViewSet.as_view({'get': 'list'})),
    # url(r'^books/(?P<pk>\d+)/$', views.BookInfoViewSet.as_view({'get': 'retrieve'})),

    # 使用ReadOnlyModelViewSet视图集
    # url(r'^books/$', views.BookInfoViewSet.as_view({'get': 'list'})),
    # url(r'^books/(?P<pk>\d+)/$', views.BookInfoViewSet.as_view({'get': 'retrieve'})),


    # 附加action动作的视图集定义
    # url(r'^books/$', views.BookInfoViewSet.as_view({'get': 'list'})),
    # url(r'^books/latest/$', views.BookInfoViewSet.as_view({'get': 'latest'})),
    # url(r'^books/(?P<pk>\d+)/$', views.BookInfoViewSet.as_view({'get': 'retrieve'})),
    # url(r'^books/(?P<pk>\d+)/read/$', views.BookInfoViewSet.as_view({'put': 'read'})),

]

# 路由器只能配置视图集使用
# SimpleRouter和DefaultRouter的区别:DefaultRouter会多配置一个根路由
router = DefaultRouter()
router.register(r'books', views.BookInfoViewSet)
urlpatterns += router.urls



# router = DefaultRouter()  # 可以处理视图的路由器
# router.register(r'books', views.BookInfoViewSet)  # 向路由器中注册视图集
# urlpatterns += router.urls   # 将路由器中的所有路由信息追到django的路由列表中